package cn.hashq.netpostclient.session;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ConcurrentHashMap;

@Data
@Slf4j
public final class SessionMap {

    private SessionMap() {
    }

    private static SessionMap singleInstance = new SessionMap();

    private ConcurrentHashMap<String, ClientSession> map = new ConcurrentHashMap<>();

    public static SessionMap inst() {
        return singleInstance;
    }

    public void addSession(ClientSession session) {
        map.put(session.getKey(), session);
    }

    public ClientSession getSession(String key) {
        return map.get(key);
    }

    public void removeSession(String sessionId) {
        if (!map.containsKey(sessionId)) return;
        map.remove(sessionId);
    }

}
